package com.fs.controller;

import com.fs.pojo.Goods;
import com.fs.vo.PageResult;
import com.fs.vo.SysResult;
import com.fs.annotation.SysLog;
import com.fs.pojo.Goods;
import com.fs.pojo.Order;
import com.fs.service.GoodsSerivce;
import com.fs.vo.GoodsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@Api(tags = "商品管理")
@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private GoodsSerivce goodsSerivce;

    @SysLog("添加商品")
    @ApiOperation(value = "添加商品")
    @RequiresPermissions({"goods:save"})
    @PostMapping("/add")
    public SysResult add(@RequestBody GoodsVO entity){
        return goodsSerivce.add(entity);
    }

//    @PutMapping("/edit")
//    public ResultVO edit(@RequestBody GoodsEntity entity){
//        return goodsSerivce.edit(entity);
//    }
//
    @SysLog("商品列表")
    @ApiOperation(value = "商品列表")
    @RequiresPermissions({"goods:list"})
    @GetMapping("/list")
    public SysResult list(PageResult request){
        return goodsSerivce.list(request);
    }

    @SysLog("修改商品状态")
    @ApiOperation(value = "修改商品状态")
    @RequiresPermissions({"goods:status"})
    @PutMapping("/updateGoodsStatus")
    public SysResult updateGoodsStatus(@RequestBody Goods entity){
        return goodsSerivce.updateGoodsStatus(entity);
    }

    /**
     * 热卖
     * @param entity
     * @return
     */
    @SysLog("修改商品状态-热卖")
    @ApiOperation(value = "修改商品状态-热卖")
    @RequiresPermissions({"goods:status:hot"})
    @PutMapping("/updateHot")
    public SysResult updateHot(@RequestBody Goods entity){
        return goodsSerivce.updateHot(entity);
    }

    /**
     * 置顶
     * @param entity
     * @return
     */
    @SysLog("修改商品状态-置顶")
    @ApiOperation(value = "修改商品状态-置顶")
    @RequiresPermissions({"goods:status:top"})
    @PutMapping("/updateTop")
    public SysResult updateTop(@RequestBody Goods entity){
        return goodsSerivce.updateTop(entity);
    }

    /**
     * 推荐
     * @param entity
     * @return
     */
    @SysLog("修改商品状态-推荐")
    @ApiOperation(value = "修改商品状态-推荐")
    @RequiresPermissions({"goods:status:Rec"})
    @PutMapping("/updateRec")
    public SysResult updateRec(@RequestBody Goods entity){
        return goodsSerivce.updateRec(entity);
    }


    @SysLog("删除商品")
    @ApiOperation(value = "删除商品")
    @RequiresPermissions({"goods:del"})
    @DeleteMapping("/deleteGoodsById")
    public SysResult deleteById(Integer id){
        return goodsSerivce.delById(id);
    }

    @SysLog("查看商品收藏用户")
    @ApiOperation(value = "查看商品收藏用户")
    @RequiresPermissions({"goods:user:fav"})
    @GetMapping("/toUserList")
    public SysResult toUserList(PageResult request){
        return goodsSerivce.toUserList(request);
    }
}
